#pragma once

#include <vector>
#include <map>
#include "Config.hpp"
#include "zen_random.h"
#include "zen_log.h"

using namespace Zen;

class Tetris
{
public: // action

	Tetris();

	void reset();

	void gen_tetris();

	void reset_current_pos();

	bool try_rotate();

	bool check_free();

	bool try_down();

	bool try_right();

	bool try_left();

	int try_quick_down();

	// return false if game finished.
	bool put_in();

	void check_result();

	void checkout();


	Result const & getResult() const { return m_result; }

	Map const & getMap() const { return m_map; }

	TetrisInfo const & getCurrentTetris() { return m_current; }

	Pos getCurrentTetrisPos() { return m_current_pos; }

	TetrisInfo const & getNextTetris() { return m_next; }

	int getScore() { return m_total_score; }
protected:
	bool _is_in_map(std::vector<Pos> const & poses);
	bool _is_in_free_space(std::vector<Pos> const & poses);
	bool _try_move(int x, int y, bool rot = false);

	TetrisInfo m_next;
	TetrisInfo m_current;
	Pos m_current_pos;
	
	Map m_map;
	Result m_result;

	int m_total_score = 0;
	std::shared_ptr<TetrisConfig> m_config;
};

